<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>添加渠道</title>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/node_modules/mockjs/dist/mock-min.js"></script>
  <link rel="stylesheet" href="__PUBLIC__/style/base.css">
  <link rel="stylesheet" href="__PUBLIC__/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="__PUBLIC__/style/qr_only.css">
</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <header class="col-xs-6 col-md-2 account_name"><img class='img-responsive' src="__PUBLIC__/images/logo_long.jpg" alt=""></header>
      <div class="col-xs-12 col-md-12">
        <div class="row">

          <!-- 左侧栏 -->
          <div class="col-md-2 manage_nav_box">
            <iframe src="{:U('nav_qudao')}?local=ziqudao_a" frameborder="0" width="100%" style="height:45rem;"></iframe>
          </div>
          <!-- end 左侧栏 -->

          <!-- 右主体  -->
          <div class="main">
            <!-- 渠道选择改动时会触发ajax，返回图片或者邀请码（用于生成code的URL也行） -->
            <input type="hidden" name="ajax_base" id="ajax_base" value = 'test.com/ajax_base'>
            <div class="title">扫码即可注册系统渠道</div>
            <select name="qudao_name" id="qudao_name" class="qudao_select">
              <!-- 这里填写可选公司渠道 -->
              <!-- 用户选择后会发出ajax获取二维码 -->
              <option value="00" style="text-align:center;">选择您的公众号渠道</option>
              <option value="01" style="text-align:center;">1</option>
              <option value="02" style="text-align:center;">2</option>
            </select>
            <div class="qr_code"><img id = 'qr_code_img' src="__PUBLIC__/images/5_0/u107.jpg" alt="qr_code"></div>
            <div class="refresh_qrcode"><button onclick="getQr()">刷新二维码</button></div>
          </div>
          <div class="wram_mess">刷新后先前二维码立刻失效</div>
          <!-- end 右主体 -->

        </div>
      </div>
    </div>
  </div>
  <script>
    var url = $('#ajax_base').val()
    function getQr () {
      // $('#qudao_name').on('change', getQr())
      var value = $('#qudao_name').val()
      $.get(`${url}?value=${value}`, function (data, status) {
        if (status === 'success') {
          $('#qr_code_img').attr('src', JSON.parse(data).img)
        }
      })
    }
    $(document).ready(function() {
      $('.messageBoxContent thead .authSetting').on('click', function (event) {
        event.stopPropagation();Array.from($('.messageBoxContent input[type=\'checkbox\']')).forEach(function(val,index){val.checked = !val.checked})
      })
      $('#qudao_name').on('change', getQr)
    })
    window.addEventListener('message', fromNav, false)
    function fromNav(event) {
      console.log(event.data.url)
      if (event.data.url.length && event.data.url.length > 1) {
        self.location = event.data.url
      }
    }
  </script>
  <script src="__PUBLIC__/script/mock.js"></script>
</body>
</html>
